﻿#include "SurfaceElectricFieldMapSidebarSettings.h"
#include "ui_SurfaceElectricFieldMapSidebarSettings.h"
#include <QVBoxLayout>
#include <QObject>
#include <QLabel>
#include <QLineEdit>
#include <QSpinBox>
#include <QComboBox>
#include <QWidget>
#include <QRegExp>
#include <QTabWidget>
#include <QTabBar>
#include <QScrollBar>
#include <QListView>
#include <QDebug>
#include <QIcon>
#include <QGroupBox>
#include <QStandardItemModel>
#include <QListWidgetItem>
#include <QCheckBox>
#include <QPushButton>
#include "SurfaceElectricFieldMapSidebarData.h"
#include "FormulaEditorDialog.h"
#include "BaseModule/IBaseSignal.h"
#include "BaseModule/GlobalHelper.h"
#include "BaseWidget/IdaDialogMsg.h"
#include "BaseWidget/IWidgetSignal.h"

namespace pst
{
    SurfaceElectricFieldMapSidebarSettings::SurfaceElectricFieldMapSidebarSettings(QWidget* parent)
        : QScrollArea(parent), _titleFontSize{ 14 }, ui(new Ui::SurfaceElectricFieldMapSidebarSettings())
    {
        ui->setupUi(this);
        // 设置基本布局属性
        setContentsMargins(0, 0, 0, 0);
        addTopTabPivotUI();
        clearControlPlane();
        ui->dockWidget_Data->setStyleSheet("QDockWidget > QWidget{border: 1px solid #EBEDEE;}");
        ui->dockWidget_DataSource->setStyleSheet("QDockWidget > QWidget{border: 1px solid #EBEDEE;}");
        ui->dockWidget_2->setStyleSheet("QDockWidget > QWidget{border: 1px solid #EBEDEE;}");
        ui->dockWidget_3->setStyleSheet("QDockWidget > QWidget{border: 1px solid #EBEDEE;}");
        ui->scrollArea->setStyleSheet("QScrollArea > QWidget{border: 0px solid #EBEDEE;}");
        ui->listWidget_Data->setWordWrap(true);
        connect(ui->listWidget_Data, &QListWidget::itemChanged, this, &SurfaceElectricFieldMapSidebarSettings::slot_itemCheckStateChanged);
        ui->lineEdit_FormulaEditor->setPlaceholderText(QStringLiteral("self"));
        
        connectSignalsAndSlots();
        hideComponents();
        m_enableStatus.resize(8);
    }

    SurfaceElectricFieldMapSidebarSettings::~SurfaceElectricFieldMapSidebarSettings()
    {
    }

    void SurfaceElectricFieldMapSidebarSettings::setMainWiondowId(int id)
    {
        m_mainWindowId = id;
    }

    QListWidgetItem* SurfaceElectricFieldMapSidebarSettings::addData(InfomationGraph3DBasical* info)
    {
        QString curveName = info->m_name;
        QListWidgetItem* listItem = new QListWidgetItem(curveName);
        listItem->setFlags(listItem->flags() | Qt::ItemIsUserCheckable);
        listItem->setCheckState(Qt::Checked);
        ui->listWidget_Data->addItem(listItem);

        m_allAddedDataList.append(qMakePair(info, listItem));
        return listItem;
    }

    void SurfaceElectricFieldMapSidebarSettings::updateInfoDataAndInterfaceToUI(
        SurfaceElectricFieldMapSidebarData* data)
    {
        //disconnectSignalsAndSlots();
        QSignalBlocker blocker3(ui->comboBox_valueData);
        QSignalBlocker blocker4(ui->checkBox_DB);
        QSignalBlocker blocker5(ui->checkBox_Normalize);
        QSignalBlocker blocker6(ui->listWidget_Data);

        clearControlPlane();

        m_currentItemData = data;

        ui->checkBox_DB->setEnabled(true);
        ui->checkBox_Normalize->setEnabled(true);
        ui->checkBox_DB->setChecked(data->getIsLog());
        ui->checkBox_Normalize->setChecked(data->getIsNormalized());
        auto allPointArray = data->getAllPointArray();
        auto allCellArray = data->getAllCellArray();
        auto currentScalarArray = data->getCurrentScalarArray();
        auto currentScalarCom = data->getCurrentScalarArrayComp();

        for (const auto& i : allPointArray)
        {
            if (i.arrayComponent == 1)
            {
                ui->comboBox_valueData->addItem(i.arrayName);
                m_addedArrayList.append(i);
            }
        }

        for (const auto& i : allCellArray)
        {
            if (i.arrayComponent == 1)
            {
                ui->comboBox_valueData->addItem(i.arrayName);
                m_addedArrayList.append(i);
            }
        }

        ui->comboBox_valueData->setCurrentText(currentScalarArray.arrayName);
        if (ui->comboBox_valueData->count() == 0)
        {
            ui->dockWidget_2->setEnabled(false);
        }
        else
        {
            ui->dockWidget_2->setEnabled(true);
        }
        ui->textEdit_DataSource->setText(data->getDataSource());

        if(ui->comboBox_valueData->count() == 0)
        {
            ui->checkBox_DB->setEnabled(false);
            ui->checkBox_Normalize->setEnabled(false);
        }
        else
        {
            ui->checkBox_DB->setEnabled(true);
            ui->checkBox_Normalize->setEnabled(true);
        }
 
        //connectSignalsAndSlots();
    }

    void SurfaceElectricFieldMapSidebarSettings::setControlPanelEditable(bool enable)
    {
        ui->listWidget_Data->setSelectionMode(QAbstractItemView::SingleSelection);

        ui->comboBox_valueData->setEnabled(enable);
        ui->comboBox_categryValue->setEnabled(enable);
        ui->checkBox_DB->setEnabled(enable);
        ui->checkBox_Normalize->setEnabled(enable);
    }

    void SurfaceElectricFieldMapSidebarSettings::addTopTabPivotUI()
    {
        addCurveListUI();
        addDataPageUI();
        addDataOptrationUI();
    }

    void SurfaceElectricFieldMapSidebarSettings::addDataPageUI()
    {
        ui->comboBox_categryValue->setEditable(false);
    }

    void SurfaceElectricFieldMapSidebarSettings::addCurveListUI()
    {
        ui->listWidget_Data->setFixedHeight(150);
        ui->listWidget_Data->setSelectionMode(QAbstractItemView::ExtendedSelection);
        ui->listWidget_Data->setEditTriggers(QAbstractItemView::NoEditTriggers);
        ui->listWidget_Data->setSelectionMode(QAbstractItemView::SingleSelection);

        //connect(ui->listWidget_Data->selectionModel(), &QItemSelectionModel::selectionChanged, this, &SurfaceElectricFieldMapSidebarSettings::slot_curveNameClicked);
        //connect(ui->listWidget_Data, &QListWidget::itemChanged, this, &SurfaceElectricFieldMapSidebarSettings::slot_itemCheckStateChanged);
        //connect(ui->listWidget_Data, &QListWidget::itemDoubleClicked, this, &SurfaceElectricFieldMapSidebarSettings::slot_itemDoubleClicked);
        //connect(ui->listWidget_Data->itemDelegate(), &QAbstractItemDelegate::closeEditor, this, &SurfaceElectricFieldMapSidebarSettings::signal_renameCheck);

        ui->listWidget_Data->setContextMenuPolicy(Qt::CustomContextMenu);
        //QObject::connect(ui->listWidget_Data, &QListWidget::customContextMenuRequested,
        //    this, &SurfaceElectricFieldMapSidebarSettings::slot_addCustomContextMenu);
    }

    void SurfaceElectricFieldMapSidebarSettings::addDataOptrationUI()
    {
        ui->checkBox_DB->setEnabled(false);
        ui->checkBox_Normalize->setEnabled(false);
        ui->checkBox_MathOperation->setEnabled(false);
        ui->lineEdit_FormulaEditor->setReadOnly(true);
        ui->pushButton_FormulaEditor->setEnabled(false);
    }

    void SurfaceElectricFieldMapSidebarSettings::hideComponents()
    {
        ui->label_categryValue->setVisible(false);
        ui->comboBox_categryValue->setVisible(false);
        ui->checkBox_MathOperation->setVisible(false);
        ui->lineEdit_FormulaEditor->setVisible(false);
        ui->pushButton_FormulaEditor->setVisible(false);

        //ui->dockWidget_3->hide();
        ui->radioButton_Amplitude->setVisible(false);     // 幅度
        ui->radioButton_Phase->setVisible(false);         // 相位
        ui->radioButton_RealPart->setVisible(false);      // 实部
        ui->radioButton_ImaginaryPart->setVisible(false); // 虚部
        //ui->checkBox_DB->setVisible(false);
        //ui->checkBox_Normalize->setVisible(false);

        ui->radioButton_Amplitude->setEnabled(false);     // 幅度
        ui->radioButton_Phase->setEnabled(false);         // 相位
        ui->radioButton_RealPart->setEnabled(false);      // 实部
        ui->radioButton_ImaginaryPart->setEnabled(false); // 虚部
    }

    void SurfaceElectricFieldMapSidebarSettings::on_pushButton_FormulaEditor_clicked()
    {
        QStringList _SelectionCurve{
            QStringLiteral("曲线1"),
        };
        auto _formulaEditorDialog = new FormulaEditorDialog();
        _formulaEditorDialog->setCurveList(_SelectionCurve);
        auto _ok = _formulaEditorDialog->execWindow();
        if (_ok)
        {
            auto _formulaContent = _formulaEditorDialog->getFormulaContent();
            ui->lineEdit_FormulaEditor->setText(_formulaContent);
        }
    }

    void SurfaceElectricFieldMapSidebarSettings::on_radioButton_Amplitude_clicked()
    {
        auto _isClicked = ui->radioButton_Amplitude->isChecked();
    }
    void SurfaceElectricFieldMapSidebarSettings::on_radioButton_Phase_clicked()
    {
        auto _isClicked = ui->radioButton_Phase->isChecked();
    }
    void SurfaceElectricFieldMapSidebarSettings::on_radioButton_RealPart_clicked()
    {
        auto _isClicked = ui->radioButton_RealPart->isChecked();
    }
    void SurfaceElectricFieldMapSidebarSettings::on_radioButton_ImaginaryPart_clicked()
    {
        auto _isClicked = ui->radioButton_ImaginaryPart->isChecked();
    }

    // 选中曲线后，判断所有选中曲线的信息，根据信息设置下面框的内内容
    void SurfaceElectricFieldMapSidebarSettings::slot_curveNameClicked()
    {
        // //TODO 发送信号给graph，通知选中该曲线
        // auto allSelectedItem = ui->listWidget_Data->selectedItems();
        // if (allSelectedItem.isEmpty())
        // {
        //     disconnectSignalsAndSlots();
        //     clearControlPlane();
        //     connectSignalsAndSlots();
        //     return;
        // }
        // ui->pushButton_FormulaEditor->setEnabled(true);
        // emit signal_chosenItemsChanged(allSelectedItem);

        auto allSelectedItem = ui->listWidget_Data->selectedItems();
        QString dataSource;
        bool _isLegalSource = true;
        QList<int> selectedItemIndexList;
        for (auto item : allSelectedItem)
        {
            selectedItemIndexList.append(ui->listWidget_Data->row(item));
            if (_isLegalSource)
            {
                // 获取数据来源（项目树）
                QString _itemText;
                emit signal_getSidebarCurveDataSource(item, _itemText);
                if (dataSource.isEmpty() || dataSource.contains(_itemText))
                    dataSource = _itemText;
                else
                {
                    dataSource = "";
                    _isLegalSource = false;
                }
            }
        }
        ui->textEdit_DataSource->setText(dataSource);
        QString selectedItemIndexListString = GlobalHelperInstance->convertIntListToQString(selectedItemIndexList);

        QStringList _pyCodes{};
        _pyCodes += QString("surfaceelectricfieldmapsidebarsettings1 = PostProcessing.SurfaceElectricFieldMapSidebarSettingsPy()");
        _pyCodes += QString("surfaceelectricfieldmapsidebarsettings1.curveNameClicked(%1,'%2')").arg((int)m_mainWindowId).arg(selectedItemIndexListString);
        emit IBaseSignalInstance->signal_execPYCode(_pyCodes, true, false);
        pyCurveNameClicked(selectedItemIndexList);
    }

    void SurfaceElectricFieldMapSidebarSettings::setControlPlaneToAnimationState(bool isAnimationState)
    {
        if (isAnimationState)
        {
            disconnectSignalsAndSlots();

            m_enableStatus[0] = ui->comboBox_categryValue->isEnabled();
            m_enableStatus[1] = ui->comboBox_valueData->isEnabled();
            m_enableStatus[2] = ui->radioButton_Amplitude->isEnabled();
            m_enableStatus[3] = ui->radioButton_Phase->isEnabled();
            m_enableStatus[4] = ui->radioButton_RealPart->isEnabled();
            m_enableStatus[5] = ui->radioButton_ImaginaryPart->isEnabled();
            m_enableStatus[6] = ui->checkBox_DB->isEnabled();
            m_enableStatus[7] = ui->checkBox_Normalize->isEnabled();

            setControlPanelEditable(false);
        }
        else
        {
            connectSignalsAndSlots();

            ui->comboBox_categryValue->setEnabled(m_enableStatus[0]);
            ui->comboBox_valueData->setEnabled(m_enableStatus[1]);
            ui->radioButton_Amplitude->setEnabled(m_enableStatus[2]);
            ui->radioButton_Phase->setEnabled(m_enableStatus[3]);
            ui->radioButton_RealPart->setEnabled(m_enableStatus[4]);
            ui->radioButton_ImaginaryPart->setEnabled(m_enableStatus[5]);
            ui->checkBox_DB->setEnabled(m_enableStatus[6]);
            ui->checkBox_Normalize->setEnabled(m_enableStatus[7]);
        }
    }

    void SurfaceElectricFieldMapSidebarSettings::slot_itemCheckStateChanged(QListWidgetItem* item)
    {
        // qDebug() << "Icon clicked in row:" << item;
        // siganl_showHideItemActor(item);

        auto index = ui->listWidget_Data->row(item);
        auto visible = item->checkState() == Qt::Checked ? true : false;

        QStringList _pyCodes{};
        _pyCodes += QString("surfaceelectricfieldmapsidebarsettings2 = PostProcessing.SurfaceElectricFieldMapSidebarSettingsPy()");
        _pyCodes += QString("surfaceelectricfieldmapsidebarsettings2.itemCheckStateChanged(%1,%2,%3)").arg((int)m_mainWindowId).arg((int)index).arg(visible);
        emit IBaseSignalInstance->signal_execPYCode(_pyCodes, true, false);
        pyItemCheckStateChanged(index, visible);
    }

    void SurfaceElectricFieldMapSidebarSettings::slot_itemDoubleClicked(QListWidgetItem* item)
    {
        emit IWidgetSignalInstance->signal_exitAddMarkerState();
        siganl_graphNameDoubleClicked(item);
    }

    void SurfaceElectricFieldMapSidebarSettings::connectSignalsAndSlots()
    {
        connect(ui->comboBox_valueData, QOverload<int>::of(&QComboBox::currentIndexChanged),
            this, &SurfaceElectricFieldMapSidebarSettings::slot_resultDataChanged);
        connect(ui->checkBox_DB, &QCheckBox::clicked, this, &SurfaceElectricFieldMapSidebarSettings::slot_updateProcessData);
        connect(ui->checkBox_Normalize, &QCheckBox::clicked, this, &SurfaceElectricFieldMapSidebarSettings::slot_updateProcessData);

        connect(ui->listWidget_Data->selectionModel(), &QItemSelectionModel::selectionChanged, this, &SurfaceElectricFieldMapSidebarSettings::slot_curveNameClicked);
        //connect(ui->listWidget_Data, &QListWidget::itemChanged, this, &SurfaceElectricFieldMapSidebarSettings::slot_itemCheckStateChanged);
        connect(ui->listWidget_Data, &QListWidget::itemDoubleClicked, this, &SurfaceElectricFieldMapSidebarSettings::slot_itemDoubleClicked,Qt::UniqueConnection);
        connect(ui->listWidget_Data->itemDelegate(), &QAbstractItemDelegate::closeEditor, this, &SurfaceElectricFieldMapSidebarSettings::signal_renameCheck);

        QObject::connect(ui->listWidget_Data, &QListWidget::customContextMenuRequested,
            this, &SurfaceElectricFieldMapSidebarSettings::slot_addCustomContextMenu);

        //connect(ui->comboBox_valueData, &PostComboBox::popupAboutToShow, this, []() {
        //    emit IWidgetSignalInstance->signal_exitAddMarkerState(); });
    }

    void SurfaceElectricFieldMapSidebarSettings::disconnectSignalsAndSlots()
    {
        disconnect(ui->comboBox_valueData, QOverload<int>::of(&QComboBox::currentIndexChanged),
            this, &SurfaceElectricFieldMapSidebarSettings::slot_resultDataChanged);
        disconnect(ui->checkBox_DB, &QCheckBox::clicked, this, &SurfaceElectricFieldMapSidebarSettings::slot_updateProcessData);
        disconnect(ui->checkBox_Normalize, &QCheckBox::clicked, this, &SurfaceElectricFieldMapSidebarSettings::slot_updateProcessData);

        disconnect(ui->listWidget_Data->selectionModel(), &QItemSelectionModel::selectionChanged, this, &SurfaceElectricFieldMapSidebarSettings::slot_curveNameClicked);
        //disconnect(ui->listWidget_Data, &QListWidget::itemChanged, this, &SurfaceElectricFieldMapSidebarSettings::slot_itemCheckStateChanged);
        disconnect(ui->listWidget_Data, &QListWidget::itemDoubleClicked, this, &SurfaceElectricFieldMapSidebarSettings::slot_itemDoubleClicked);
        disconnect(ui->listWidget_Data->itemDelegate(), &QAbstractItemDelegate::closeEditor, this, &SurfaceElectricFieldMapSidebarSettings::signal_renameCheck);

        QObject::disconnect(ui->listWidget_Data, &QListWidget::customContextMenuRequested,
            this, &SurfaceElectricFieldMapSidebarSettings::slot_addCustomContextMenu);
    }

    void SurfaceElectricFieldMapSidebarSettings::slot_resultDataChanged(int index)
    {
        // // 更新acotr数据
        // // m_currentItemData->setCurrentValueIndex(index);
        // m_currentItemData->setCurrentScalarArray(m_addedArrayList[index]);
        // emit signal_updateActorValue(m_currentItemData);
        emit IWidgetSignalInstance->signal_exitAddMarkerState();

        QStringList _pyCodes{};
        _pyCodes += QString("surfaceelectricfieldmapsidebarsettings7 = PostProcessing.SurfaceElectricFieldMapSidebarSettingsPy()");
        _pyCodes += QString("surfaceelectricfieldmapsidebarsettings7.resultDataChanged(%1,%2)").arg((int)m_mainWindowId).arg((int)index);
        emit IBaseSignalInstance->signal_execPYCode(_pyCodes, true, false);
        pyResultDataChanged(index);
    }

    void SurfaceElectricFieldMapSidebarSettings::slot_updateProcessData()
    {
        emit IWidgetSignalInstance->signal_exitAddMarkerState();
        bool isLog = ui->checkBox_DB->isChecked();
        bool isNormalize = ui->checkBox_Normalize->isChecked();
        QStringList _pyCodes{};
        _pyCodes += QString("surfaceelectricfieldmapsidebarsettings6 = PostProcessing.SurfaceElectricFieldMapSidebarSettingsPy()");
        _pyCodes += QString("surfaceelectricfieldmapsidebarsettings6.updateProcessData(%1,%2,%3)").arg(m_mainWindowId).arg((int)isLog).arg((int)isNormalize);
        emit IBaseSignalInstance->signal_execPYCode(_pyCodes, true, false);

        pyUpdateProcessData(isLog, isNormalize);
    }

    void SurfaceElectricFieldMapSidebarSettings::pyCurveNameClicked(QList<int> selectedIndexs)
    {
        QList<QListWidgetItem*> allSelectedItem;
        {
            QSignalBlocker blocker(ui->listWidget_Data);

            for (int i = 0; i < selectedIndexs.size(); i++)
            {
                QListWidgetItem* item = ui->listWidget_Data->item(selectedIndexs.at(i));
                item->setSelected(true);
                allSelectedItem.append(item);
            }
        }
        if (allSelectedItem.isEmpty())
        {
            disconnectSignalsAndSlots();
            clearControlPlane();
            connectSignalsAndSlots();
            return;
        }
        ui->pushButton_FormulaEditor->setEnabled(true);
        emit signal_chosenItemsChanged(allSelectedItem);
    }

    void SurfaceElectricFieldMapSidebarSettings::pyResultDataChanged(int index)
    {
        QSignalBlocker blocker(ui->comboBox_valueData);
        ui->comboBox_valueData->setCurrentIndex(index);
        m_currentItemData->setCurrentScalarArray(m_addedArrayList[index]);
        emit signal_updateActorValue(m_currentItemData);
    }

    void SurfaceElectricFieldMapSidebarSettings::pyUpdateProcessData(bool isLog, bool isNormalize)
    {
        QSignalBlocker blocker1(ui->checkBox_DB);
        QSignalBlocker blocker2(ui->checkBox_Normalize);

        ui->checkBox_DB->setChecked(isLog);
        ui->checkBox_Normalize->setChecked(isNormalize);

        m_currentItemData->setIsLog(isLog);
        m_currentItemData->setIsNormalized(isNormalize);
        emit signal_updateActorValue(m_currentItemData);
    }

    void SurfaceElectricFieldMapSidebarSettings::pyDeleteSurfaceElectricFieldMap(QString selectedIndexs)
    {
        QStringList rowIndexsStr = selectedIndexs.split("_");
        QList<QListWidgetItem*> itemList;
        for (QString rowIndexStr : rowIndexsStr)
        {
            int rowIndex = rowIndexStr.toInt();
            itemList.append(ui->listWidget_Data->item(rowIndex));
        }
        emit signal_deleteChosenGraphs(itemList);
    }

    void SurfaceElectricFieldMapSidebarSettings::pyItemCheckStateChanged(int itemIndex, bool visible)
    {
        auto item = ui->listWidget_Data->item(itemIndex);
        if (!item)
            return;
        {
            QSignalBlocker blocker(ui->listWidget_Data);
            item->setCheckState(visible ? Qt::Checked : Qt::Unchecked);
        }
        siganl_showHideItemActor(item);
    }

    void SurfaceElectricFieldMapSidebarSettings::clearControlPlane()
    {
        QSignalBlocker blocker(ui->comboBox_valueData);
        QSignalBlocker blocker2(ui->checkBox_DB);
        QSignalBlocker blocker3(ui->checkBox_Normalize);

        m_addedArrayList.clear();
        ui->comboBox_valueData->clear();
        ui->checkBox_DB->setChecked(false);
        ui->checkBox_Normalize->setChecked(false);
        ui->checkBox_DB->setEnabled(false);
        ui->checkBox_Normalize->setEnabled(false);
    }

    QListWidget* SurfaceElectricFieldMapSidebarSettings::getCurveNameListWidget()
    {
        return ui->listWidget_Data;
    }

    void SurfaceElectricFieldMapSidebarSettings::slot_addCustomContextMenu(const QPoint& pos)
    {
        auto selectedItems = ui->listWidget_Data->selectedItems();
        if (selectedItems.isEmpty())
        {
            return;
        }

        QMenu contextMenu(this);
        QAction* deleteChosenGraphs = contextMenu.addAction("删除选中的图像");
        QObject::connect(deleteChosenGraphs, &QAction::triggered, this,
            [this]()
            {
                emit IWidgetSignalInstance->signal_exitAddMarkerState();

                QList<QListWidgetItem*> itemList = ui->listWidget_Data->selectedItems();
                QString selectedIndexs;
                for (QListWidgetItem* item : itemList)
                {
                    int rowIndex = ui->listWidget_Data->row(item);
                    selectedIndexs.append("_").append(QString::number(rowIndex));
                }
                selectedIndexs = "'" + selectedIndexs.right(selectedIndexs.length() - 1) + "'";
                QStringList _pyCodes{};
                _pyCodes += QString("surfaceelectricfieldmapsidebarsettings4 = PostProcessing.SurfaceElectricFieldMapSidebarSettingsPy()");
                _pyCodes += QString("surfaceelectricfieldmapsidebarsettings4.deleteSurfaceElectricFieldMap(%1,%2)").arg((int)m_mainWindowId).arg(selectedIndexs);
                emit IBaseSignalInstance->signal_execPYCode(_pyCodes, true, false);

                emit signal_deleteChosenGraphs(ui->listWidget_Data->selectedItems());
            });

        if (selectedItems.size() == 1)
        {
            QAction* renameGraphs = contextMenu.addAction("重命名");
            QObject::connect(renameGraphs, &QAction::triggered, this, &SurfaceElectricFieldMapSidebarSettings::slot_renameItem);
        }

        contextMenu.exec(ui->listWidget_Data->mapToGlobal(pos));
    }

    void SurfaceElectricFieldMapSidebarSettings::slot_renameItem()
    {
        emit IWidgetSignalInstance->signal_exitAddMarkerState();
        auto selectedItems = ui->listWidget_Data->selectedItems();
        if (selectedItems.size() != 1)
        {
            return;
        }

        auto item = selectedItems[0];
        item->setFlags(item->flags() | Qt::ItemIsEditable);
        ui->listWidget_Data->editItem(item);
    }

} // namespace pst
